package com.tianhui.consignortwofei.mvp.ui.activity;

import android.os.Bundle;
import android.text.TextUtils;
import android.widget.ImageView;
import android.widget.TextView;

import com.fgs.common.CommonFragment;
import com.fgs.common.CommonPresenter;
import com.fgs.common.CommonView;
import com.tianhui.consignortwofei.R;
import com.tianhui.consignortwofei.base.BaseActivity;
import com.tianhui.consignortwofei.constant.KeyValue;
import com.tianhui.consignortwofei.constant.OrderType;
import com.tianhui.consignortwofei.mvp.model.enty.OrderInfo;
import com.tianhui.consignortwofei.pattern.orderAdjust.IOrderAdjust;
import com.tianhui.consignortwofei.pattern.orderAdjust.impl.DeliverConfirm;
import com.tianhui.consignortwofei.pattern.orderAdjust.impl.LoadingConfirm;
import com.tianhui.consignortwofei.pattern.orderAdjust.impl.PriceAdjust;
import com.tianhui.consignortwofei.pattern.orderAdjust.impl.QuantityAdjust;
import com.tianhui.consignortwofei.pattern.orderAdjust.impl.RoadAdjust;
import com.tianhui.consignortwofei.pattern.orderAdjust.impl.UnloadTimeAdjust;
import com.tianhui.consignortwofei.pattern.orderAdjust.impl.WeightAdjust;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * @author fgs
 * @date 2020/9/2
 * @description
 **/
public class AdjustSuccessActivity extends BaseActivity {

    @BindView(R.id.layout_adjust_success_originalTextView)
    TextView mOriginalTextView;
    @BindView(R.id.layout_adjust_success_adjustTextView)
    TextView mAdjustTextView;
    @BindView(R.id.layout_adjust_success_adjustImageView)
    ImageView mAdjustImageView;
    @BindView(R.id.layout_adjust_success_successTipTextView)
    TextView mSuccessTipTextView;
    private IOrderAdjust iOrderAdjust;
    private OrderInfo orderInfo;
    private String value;

    @Override
    public int getLayoutId() {
        return R.layout.activity_adjust_success;
    }

    @Override
    public CommonPresenter createPresenter() {
        return null;
    }

    @Override
    public CommonView createView() {
        return null;
    }

    @Override
    public void init() {

        Bundle bundle = getIntent().getExtras();
        if (bundle != null && !bundle.isEmpty()) {
            int type = bundle.getInt(KeyValue.KEY_TYPE);
            orderInfo = bundle.getParcelable(KeyValue.KEY_ORDER_INFO);
            value = bundle.getString(KeyValue.KEY_VALUE);
            iOrderAdjust = createOrderAdjustStatus(type);
            if (iOrderAdjust != null && orderInfo != null) {
                String originalValue = iOrderAdjust.getOriginalValue(orderInfo);
                mOriginalTextView.setText(TextUtils.isEmpty(originalValue) ? "0": originalValue);
                mAdjustTextView.setText(value);
            }
        }

    }

    private IOrderAdjust createOrderAdjustStatus(int type) {

        switch (type) {
            case OrderType.TYPE_ADJUST_PRICE:
                getToolbarStatus().setTitle("调整成功");
                mSuccessTipTextView.setText("调整成功");
                return new PriceAdjust();
            case OrderType.TYPE_ADJUST_WEIGHT:
                getToolbarStatus().setTitle("调整成功");
                mSuccessTipTextView.setText("调整成功");
                return new WeightAdjust();
            case OrderType.TYPE_ADJUST_QUANTITY:
                getToolbarStatus().setTitle("调整成功");
                mSuccessTipTextView.setText("调整成功");
                return new QuantityAdjust();
            case OrderType.TYPE_LOADING_CONFIRM:
                getToolbarStatus().setTitle("装车成功");
                mSuccessTipTextView.setText("装车成功");

                LoadingConfirm loadingConfirm = new LoadingConfirm();
                mOriginalTextView.setText(loadingConfirm.getOriginalValue(orderInfo) + "吨");
                mAdjustTextView.setText(value + "吨");
                return loadingConfirm;
            case OrderType.TYPE_DELIVER_CONFIRM:
                getToolbarStatus().setTitle("收货成功");
                mSuccessTipTextView.setText("收货成功");
                DeliverConfirm deliverConfirm = new DeliverConfirm();
                mOriginalTextView.setText(deliverConfirm.getOriginalValue(orderInfo) + "吨");
                mAdjustTextView.setText(value + "吨");
                return deliverConfirm;
            case OrderType.TYPE_ADJUST_ROAD:
                getToolbarStatus().setTitle("调整成功");
                mSuccessTipTextView.setText("调整成功");
                return new RoadAdjust();
            case OrderType.TYPE_UNLOAD_TIME:
                getToolbarStatus().setTitle("调整成功");
                mSuccessTipTextView.setText("调整成功");
                return new UnloadTimeAdjust();
        }
        return null;
    }

    @Override
    public CommonFragment createFragment() {
        return null;
    }

    @OnClick(R.id.layout_adjust_success_backButton)
    public void back() {
        finish();
    }
}
